// index.js
// 获取应用实例
const app = getApp()
import user from '../../utils/user.js'
import global from '../../utils/global'
Page({
    data: {
        top: app.globalData.menuTop,
        version: '',
        isCheckbox: false
    },
    onLoad() {
        this.setData({
            version: user.system.version
        })
        console.log(this.data.version, 'version')
        console.log('login已获取用户的', user)
    },
    //  兼容低版本获取用户信息
    onGitUserInfo() {
        if (this.data.isCheckbox) {
            wx.getUserProfile({
                lang: 'zh_CN',
                desc: '向团队成员展示头像信息',
                success: (res) => {
                    console.log(res)
                    user.avatarUrl = res.userInfo.avatarUrl
                    wx.navigateTo({
                        // url: '/pages/basic-form/basic-form'
                        url: '/pages/loginType/loginType'
                    })
                },
            })
        } else {
            return
        }
    },
    // 高版本获取用户信息
    getUser(event) {
        console.log(event, '打印啦')
        wx.uploadFile({
            url: global.baseUrl + '/api/v1/pay/wesure-report-case/upload',
            filePath: event.detail.avatarUrl,
            name: 'file',
            formData: {
                usePath: '1'
            },
            success: (res) => {
                console.log(JSON.parse(res.data).data.fileUrl, '上传成功')
                user.avatarUrl = JSON.parse(res.data).data.fileUrl
                wx.navigateTo({
                    // url: '/pages/basic-form/basic-form'
                    url: '/pages/loginType/loginType'
                })
            }

        })
    },
    closeVideo() {
        app.toast('感谢您的观看，点击授权立即体验吧！')
        // setTimeout(() => {
        this.setData({
            videoStatus: false
        })
        // }, 600);
    },
    completeVideo() {
        this.closeVideo()
    },
    onCheckbox() {
        this.setData({
            isCheckbox: !this.data.isCheckbox
        })
    },
    toPrivacy() {
        wx.navigateTo({
            url: '/packageProtocol/privacy/privacy',
        })
    },
    toService() {
        wx.navigateTo({
            url: '/packageProtocol/service/service',
        })
    }
})